package com.zpp.wedding_admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zpp.wedding_admin.entity.Good;
import com.zpp.wedding_admin.service.IGoodService;
import com.zpp.wedding_admin.utils.LQWUtils;
import com.zpp.wedding_common.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(description = "点赞管理")
@CrossOrigin
@RestController
@RequestMapping("/weddingadmin/good")
public class GoodController {
    @Autowired
    private IGoodService goodService;

    @ApiOperation(value = "获取所有点赞帖子")
    @GetMapping("getGood/{id}")
    public R getGood(@PathVariable String id) {
        List<Good> goodList = goodService.getGood(id);
        return R.ok().data("goodList", goodList);
    }

    @ApiOperation(value = "是否点赞当前文章")
    @GetMapping("isGoodWork/{id}/{userId}")
    public R isGoodWork(@PathVariable Integer id, @PathVariable Integer userId) {
        LambdaQueryWrapper<Good> lqw = LQWUtils.getLqw(Good.class);
        lqw.eq(Good::getUserId, userId).eq(Good::getWorkId, id);
        Good good = goodService.getOne(lqw);
        if ( good != null ) {
            return R.ok().data("isGood", true);
        } else {
            return R.ok().data("isGood", false);
        }
    }
}
